<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('用户列表')" />
    <th:block th:include="include :: bootstrap-editable-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>昵称：</label>
                                <input type="text" name="nickname"/>
                            </li>
                           <!-- <li>
                                <label>头像：</label>
                                <input type="text" name="headImg"/>
                            </li>-->
                           <!-- <li>
                                <label>快手id：</label>
                                <input type="text" name="kuaiId"/>
                            </li>-->
                            <li>
                                <label>快手号：</label>
                                <input type="text" name="kuaiNumber"/>
                            </li>
                            <li>
                                <label>用户ID：</label>
                                <input type="text" name="id"/>
                            </li>
                            <li>
                                <label>余额：</label>
                                <input type="text" name="balance"/>
                            </li>
                            <li>
                                <label>积分：</label>
                                <input type="text" name="integral"/>
                            </li>
                            <li>
                                <label>是否正常：</label>
                                <select name="isDisable">
                                    <option value="">所有</option>
                                    <option value="1">正常</option>
                                    <option value="0">封禁</option>
                                </select>
                            </li>
                            <li>
                                <label>等级：</label>
                                <input type="text" name="level"/>
                            </li>
                          <!--  <li>
                                <label>用户组：</label>
                                <select name="userGroup">
                                    <option value="">所有</option>
                                    <option value="普通用户">普通用户</option>
                                    <option value="代理用户">代理用户</option>
                                </select>
                            </li>-->
                            <!--<li>
                                <label style="width: 120px;">奖励总金额：</label>
                                <input type="text" name="money"/>
                            </li>-->
                            <li>
                                <label>提成比例：</label>
                                <input type="text" name="commission"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <!--<div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="whzj:user:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="whzj:user:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="whzj:user:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="whzj:user:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>-->
            <div class="col-sm-12 select-table table-striped" style="min-height:60%;">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: bootstrap-table-editable-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('whzj:user:edit')}]];
        var removeFlag = [[${@permission.hasPermi('whzj:user:remove')}]];
        var prefix = ctx + "whzj/user";

        $(function() {
            var options = {
                url: prefix + "/listProxy",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                modalName: "用户",
                detailView: true,
                onEditableSave: onEditableSave,
                onExpandRow : function(index, row, $detail) {
                    initChildTable(index, row, $detail);
                },
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '用户ID',
                },
                {
                    field: 'nickname',
                    title: '昵称'
                },
                {
                    field: 'headImg',
                    title: '头像',
                    formatter: function(value, row, index) {
                        return $.table.imageView(value);
                    }
                }/*,
                {
                    field: 'kuaiId',
                    title: '快手id'
                }*/,
                {
                    field: 'kuaiNumber',
                    title: '快手号'
                },
                {
                    field: 'balance',
                    title: '余额'
                },
                    {
                        field: 'userWithDraw',
                        title: '已提现金额'
                    },
                {
                    field: 'integral',
                    title: '积分'
                },
                {
                    field: 'isDisable',
                    title: '是否正常'
                },
                {
                    field: 'levelName',
                    title: '等级'
                },
                {
                    field: 'userGroup',
                    title: '用户组'
                },
                {
                    field: 'money',
                    title: '奖励总金额'
                },
                {
                    field: 'commission',
                    title: '一级提成比例',
                    editable: {
                        type: 'text',
                        title: '一级提成比例',
                        validate: function (v) {
                            debugger;
                            if (!v) return '不能为空';
                        }
                    },
                },
                    {
                        field: 'secondDistirrate',
                        title: '二级提成比例',
                        editable: {
                            type: 'text',
                            title: '二级提成比例',
                            validate: function (v) {
                                debugger;
                                if (!v) return '不能为空';
                            }
                        },
                    },
                    {
                        field: 'createTime',
                        title: '注册时间'
                    }/*,
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }*/]
            };
            $.table.init(options);
        });

        initChildTable = function(index, row, $detail) {
            var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
            $(childTable).bootstrapTable({
                id: "bootstrap-table2",
                url: prefix + "/listChild",
                modalName: "下级用户",
                method: 'post',
                sidePagination: "server",
                rowStyle: rowStyle,
                contentType: "application/x-www-form-urlencoded",
                queryParams : {
                    mid: row.id
                },
                columns: [
                    {
                        field: 'proxyLevel',
                        title: '用户级别'
                    },
                    {
                        field: 'id',
                        title: '用户ID',
                    },
                    {
                        field: 'nickname',
                        title: '昵称'
                    },
                    {
                        field: 'headImg',
                        title: '头像',
                        formatter: function(value, row, index) {
                            return $.table.imageView(value);
                        }
                    },
                    {
                        field: 'kuaiNumber',
                        title: '快手号'
                    },
                    {
                        field: 'createTime',
                        title: '注册时间'
                    }],
            });

        };

        function rowStyle(row, index) {
            //这里有5个取值代表5中颜色['active', 'success', 'info', 'warning', 'danger'];
            var strclass = "";
            if (row.proxyLevel == "一级代理用户") {
                strclass = 'danger';
            }
            else {
                    strclass = 'warning';
            }
            return { classes: strclass }
        }

        function onEditableSave (field, row, oldValue, $el) {
            debugger;
            if(field == 'commission'){
                //修改一级提成比例
                $.ajax({
                    type: "post",
                    url: prefix + "/modifyRate?id="+row.id+"&rate="+row.commission+"&type=1",
                    success: function(r) {
                        $.modal.msgSuccess("修改成功");
                        $.modal.reload();
                    }
                });
            }
            if(field == 'secondDistirrate'){
                //修改二级提成比例
                $.ajax({
                    type: "post",
                    url: prefix + "/modifyRate?id="+row.id+"&rate="+row.secondDistirrate+"&type=2",
                    success: function(r) {
                        $.modal.msgSuccess("修改成功");
                        $.modal.reload();
                    }
                });
            }

        }
    </script>
</body>
</html>